<div class="layui-card">
    <div class="layui-card-header">
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>黑名单信息</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <form class="layui-form toolbar nowrap">
            搜索：
            <input id="test-search-value" class="layui-input search-input" type="text" placeholder="输入ID"/>&emsp;
            <button id="test-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </form>
        <table class="layui-table" id="test-blackListTable" lay-filter="table-blackListTable"></table>
    </div>
</div>

<script type="text/html" id="blackListTableDemo">
    <a class="layui-btn layui-btn-xs" lay-event="removeBlackList">移除黑名单</a>
</script>

<script>
    layui.use(['form', 'table', 'util', 'config', 'admin','laydate','layer'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var util = layui.util;
        var admin = layui.admin;
        var laydate = layui.laydate;
        var layer = layui.layer;
        // 渲染表格
        table.render({
            elem: '#test-blackListTable',
            url: config.base_server + 'api-operation/playerList/getBlackListAll',
            method: 'GET',
            where: {
                access_token: config.getToken().access_token
            },
            page: true,
            cols: [[
                <!--{type: 'numbers'},-->
                {field: 'playerId', sort: true,width:150, title: '玩家ID'},
                {field: 'name', title: '玩家昵称'},
                {field: 'renamed', sort: true, title: '该玩家是否改名',templet:function(d){
                    return  d.renamed ==  0 ? "是":"否";
                }},
                {field: 'guest',width:120, sort: true, title: '游客',templet:function(d){
                    return  d.guest ==  0 ? "是":"否";
                }},
                {field: 'timeByTotal', title: '总在线时长(小时)',templet:function(d){
                    var date = d.timeByTotal / 1000 / 60 / 60 ;
                    date = date.toFixed(2);
                    return date;
                }},
                {field: 'online',width:120, sort: true, title: '在线',templet:function(d){
                    return  d.online ==  0 ? "否":"是";
                }},
                {field: 'dayByTotal', sort: true, title: '总在线天数'},
                {fixed: 'right',  align:'center', toolbar: '#blackListTableDemo'}
            ]]
        });
        //监听工具条:lay-event对应值
        table.on('tool(table-blackListTable)', function (obj) {
            var data = obj.data;
            var event = obj.event;
            if (event === 'removeBlackList') {
                removeBlackList(data);
            }
        });

        var removeBlackList = function (data) {
            $.ajax({
                type : 'GET',
                url : config.base_server + 'api-operation/playerList/removeBlackList',
                data : {access_token : config.getToken().access_token,playerId : data.playerId} ,
                error : function(data) {
                    alert(data.resp_msg);
                },
                success : function(data) {
                    alert(data.resp_msg);
                }
            });
            table.reload('test-blackListTable');
        };
        // 搜索按钮点击事件
        $('#test-btn-search').click(function () {
            var playerId = $('#test-search-value').val();
            table.reload('test-blackListTable', {where: {playerId : playerId}});
        });
    });
</script>
